﻿using System;
using System.Web.UI;
using Portal.Data;
using Portal.Data.Config;
using Portal.Data.Entity;
using Portal.Data.Webparts;

public partial class Webparts_Templates_truyen_PagingByType : WebpartControl
{
    public override WebpartConfig NewConfig
    {
        get { return new ContentPagingConfig(); }
    }

    public ContentPagingConfig PartConfig
    {
        get { return (ContentPagingConfig)Config; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var pageindex = Common.GetCurrentPageIndex();
            var id = Convert.ToInt32(Common.GetViewId());            
            var bType = (id > 0) ? HistoryType.FindByPrimaryKey(id) : null;
            if (bType != null)
            {
                ltrHeader.Text = bType.FullName;
                var books = Book.PagingByType(bType.ID, pageindex);
                Items.DataSource = books;
                Items.DataBind();
                Common.PagingWithouTotalCount(new Control[] {phPagingTop, phPagingBottom }, pageindex, books.Count);

                //meta
                var metatag = new LiteralControl { Text = string.Format("<meta name='description' content='{0}'/>", bType.FullName) };
                Page.Header.Controls.Add(metatag);

                Page.Title = string.Format("Thể loại " + bType.FullName + " - " + Common.GetString("Default", "PortalTitle")) + PortalContext.TitleExtension(Request);
            }
            else
            {
                HistoryTypes.DataSource = HistoryType.ListAll();
                HistoryTypes.DataBind();

                //get all
                ltrHeader.Text = string.Format("Danh sách truyện");
                var books = Book.PagingFrontEnd(pageindex);
                Items.DataSource = books;
                Items.DataBind();
                Common.PagingWithouTotalCount(new Control[] { phPagingBottom }, pageindex, books.Count);

                //meta
                var metatag = new LiteralControl { Text = string.Format("<meta name='description' content='{0} trên {1}'/>", ltrHeader.Text, Common.GetString("Default", "PortalTitle")) };
                Page.Header.Controls.Add(metatag);

                Page.Title = string.Format(ltrHeader.Text + " - " + Common.GetString("Default", "PortalTitle")) + PortalContext.TitleExtension(Request);
            }
        }
    }
}